/**
 * 日期格式化
 * @author Jason
 * @param {String} stringTime  日期字符串
 * @return String
 */
 function  dateFormat(stringTime)  
 {
 var  minute  =  1000  *  60;
 var  hour  =  minute  *  60;
 var  day  =  hour  *  24;
 var  week  =  day  *  7;
 var  month  =  day  *  30;
 
     var  time1  =  new  Date().getTime();//当前的时间戳
     console.log(time1);
     var  time2  =  Date.parse(new  Date(stringTime));//指定时间的时间戳
     console.log(time2);
     var  time  =  time1  -  time2;
 
     var  result  =  null;
     if  (time  <  0)  {
         alert("设置的时间不能早于当前时间！");
     }  else  if  (time  /  month  >=  1)  {
         result  =  "发布于"  +  parseInt(time  /  month)  +  "月前！";
     }  else  if  (time  /  week  >=  1)  {
         result  =  "发布于"  +  parseInt(time  /  week)  +  "周前！";
     }  else  if  (time  /  day  >=  1)  {
         result  =  "发布于"  +  parseInt(time  /  day)  +  "天前！";
     }  else  if  (time  /  hour  >=  1)  {
         result  =  "发布于"  +  parseInt(time  /  hour)  +  "小时前！";
     }  else  if  (time  /  minute  >=  1)  {
         result  =  "发布于"  +  parseInt(time  /  minute)  +  "分钟前！";
     }  else  {
         result  =  "刚刚发布！";
     }
     console.log(result);
     return result
 }
 //  dateFormat("2021-11-26 11:27:12");

 

/**
 * 判断浏览器内核
 * @author Jason
 * @returns Object
 */
 function browserData() 
 {
     var u = navigator.userAgent;
     return {
             trident: u.indexOf('Trident') > -1, //IE内核
             presto: u.indexOf('Presto') > -1, //opera内核
             webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
             gecko: u.indexOf('Firefox') > -1, //火狐内核Gecko
             mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
             ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios
             android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android
             iPhone: u.indexOf('iPhone') > -1 , //iPhone
             iPad: u.indexOf('iPad') > -1, //iPad
             webApp: u.indexOf('Safari') > -1 //Safari
         }
     }
 // console.log(browserData())
 
 
 
 /**
  * @author Jason
  * 判断是否是移动端
  * @returns Boolean
  */
 function isM()
 {
     var browser = {
         versions: function() {
           var u = navigator.userAgent;
           return {
                   mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                   ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios
                   android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android
                   iPhone: u.indexOf('iPhone') > -1 , //iPhone
                   iPad: u.indexOf('iPad') > -1, //iPad
                   webApp: u.indexOf('Safari') > -1 //Safari
               };
           }
       }
       if (browser.versions.mobile || browser.versions.ios || browser.versions.android || browser.versions.iPhone || browser.versions.iPad) {
         //   alert('移动端');
         return true
       }else{
         //   alert('PC')
         return false 
     }
 }
 
 
 
 /**
  * 判断是否是微信浏览器
  * @author Jason
  * @returns Boolean
  */
 function is_weixn() {
     var ua = navigator.userAgent.toLowerCase();
     if (ua.match(/MicroMessenger/i) == "micromessenger") {
         return true;
     } else {
         return false;
     }
 }
 // alert(is_weixn())
 
 

 /**
 * 获取地址栏参数
 * @param {String} key 
 * @returns String
 */

function getParams(key)
{
       let query = window.location.search.substring(1);
       query = decodeURI(query)
       let vars = query.split("&");
       for (var i=0;i<vars.length;i++) 
       {
       		var tempArr = vars[i].split("=");
       		if(tempArr[0] == key) return tempArr[1]
       }
       return false;
}

// console.log(getParams('uname'))